<template>
  <div class="app">
      <div class="wrapper">
          <input type="text" placeholder="用户名" v-model="un">
          <hr />
          <input type="password" placeholder="密码" v-model="up">
          <hr />
      </div>
      <div class="buttons">
          <button class="register" @click="register">用户注册</button>
          <button class="login" @click="login">登陆</button>
      </div>
      <router-link to="/User/register">
          <!-- <Register></Register> -->
          <div>注册页面</div>
      </router-link>
      <router-view/>
  </div>
</template>
<script>
// import Register from '@/components/user/URegister'
import axios from 'axios'
import md5 from 'js-md5'
let Base64 = require('js-base64').Base64
import Cookie from '@/assets/js/cookies.js'
// import Base64 from 'js-base64'
export default {
    name: 'User',
    // components: {
    //     'Register': Register
    // },
    data () {
        return {
            un: '',
            up: ''
        }
    },
    methods: {
        login () {
            let un = this.un
            let up = this.up
            
            console.log(md5(un))
            console.log(md5(up))
            
            let b64 = Base64.encode(un)
            console.log(b64)
            console.log(Base64.decode(b64))
            
            b64 = Base64.encode(md5(un))
            console.log(b64)
            console.log(Base64.decode(b64))
            
            
            Cookie.setCookie('zxx','222222222222')
            console.log(document.cookie)
            console.log(typeof(document.cookie))
            console.log(Cookie.getCookie('lmz'))
            

        },
        register () {
            let url = 'http://192.168.0.59:8080/user/register'
            axios.post(url,{
                uname: 'lmz',
                upassword: '123456789'
            }).then(res => {
                console.log(res.data);
                
                let resdata = res.data;
                if(resdata.reason == ''){
                    console.log(resdata.result.msg);
                }else{
                    console.log(resdata.reason);
                }
            }).catch(err => {
                console.log(err)
            })
        }
    }
}
</script>
<style lang="stylus" scoped>
    .app
        padding .2rem
        font-size .44rem
        .wrapper
            height 0
            padding-bottom 4.4rem
            margin-bottom .2rem
            input
                height 2rem
        .buttons
            text-align center
            .register,.login
                height 10vw
                width 30vw
                background-color blue
                color #fff
                font-size .44rem
</style>
